/**
 * Created by Jerry on 16/2/1.
 */
laAir.controller('laAir_cityCtl', ['$window', '$document', '$scope','$filter', 'laUserService', 'laFlightService', 'laGlobalLocalService',function ($window, $document, $scope,$filter,laUserService, laFlightService, laGlobalLocalService) {
    $scope.CityList={};
    $scope.CityFlag=0;//默认为出发城市，1为到达城市
    $scope.SearchPageProperty={
        Type:"Function",
        Id:"pageSearch",
        name:"城市选择",
        Url:"http://172.25.1.35:200/citypage.html",
        Serial:"",
        ToFrame:"main",
        HasFoot:false,
        Height:"240px"
    }
    laUserService.QueryAirportInfo("", function (backData, status) {
        $scope.CityList = backData.Result;
    });
    $scope.chooseCity=function (CityInfo) {
        laGlobalLocalService.toScreen($scope.SearchPageProperty);
        if($scope.CityFlag==0){
            $scope.BackInfo.FromCityCode=CityInfo.AirportFrom;
            $scope.BackInfo.FromCityCH=CityInfo.AirportFromCH;
        }else {
            $scope.BackInfo.ToCityCode=CityInfo.AirportTo;
            $scope.BackInfo.ToCityCH=CityInfo.AirportToCH;
        }
        var CacheData={
        Type:"Function",
        name:laGlobalProperty.laServiceConst_TransData_CityChooseInfo,
        value:JSON.stringify($scope.BackInfo),
        ToFrame:"main",
        Serial:"",

        }
        laGlobalLocalService.setLocalCacheByFrame(CacheData);
        $window.history.back();
    }
    $window.addEventListener('message', function(e) {
        filter(e.data);
    }, false);
    //广播过滤器
    function filter(data) {

        if (data.To.Target == "monitorKey") {

            if (data.Type == "Function") {
                distribute(data, data.To.Func, data.Content);
            } else if (data.Type == "Data") {
            }
        }
    }
    //广播分发器
    function distribute(data, func, content) {
        if(func=="backKey"){
           laGlobalLocalService.toScreen($scope.SearchPageProperty);
            $window.history.back();
        }else {
            return false;
        }
    }

}]);